package bravo.xc.com.xc_bravo_android.operation.bankcard.bankcard;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import bravo.xc.com.xc_bravo_android.R;
import bravo.xc.com.xc_bravo_android.adapter.bankcardListViewAdapter;
import bravo.xc.com.xc_bravo_android.base.BaseMVPActivity;
import bravo.xc.com.xc_bravo_android.beans.CommonBeans;
import bravo.xc.com.xc_bravo_android.beans.GetCardResultBeans;
import bravo.xc.com.xc_bravo_android.operation.bankcard.addbank.AddBankcardActivity;
import butterknife.ButterKnife;
import butterknife.Unbinder;

public class BankcardActivity extends BaseMVPActivity<BankCardContract.BankCardView,BankCardContract.BankCardPresenter> implements BankCardContract.BankCardView,View.OnClickListener{

    private LinearLayout layout_title_left;
    private TextView tv_title_meg;
    private RelativeLayout layout_addBankcard;
    private ListView listView_card;
    private CommonBeans commonBeans;
    private GetCardResultBeans getCardResultBeans;
    private bankcardListViewAdapter bankcardListViewAdapter;

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.layout_addBankcard:
                Intent intent=new Intent(BankcardActivity.this,AddBankcardActivity.class);
                startActivity(intent);
                break;
            case R.id.layout_title_left:
                finish();
                break;
        }
    }

    @Override
    public void showToast(String str) {
        Toast.makeText(BankcardActivity.this,str,Toast.LENGTH_SHORT).show();
    }

    @Override
    protected BankCardContract.BankCardPresenter createPresnter() {
        return new BankCardPresenter();
    }

    @Override
    protected void initView() {
        layout_title_left=(LinearLayout)findViewById(R.id.layout_title_left);
        layout_title_left.setOnClickListener(this);
        tv_title_meg=(TextView)findViewById(R.id.tv_title_msg);
        tv_title_meg.setText("我的银行卡");
        listView_card = (ListView) findViewById(R.id.lv_bankcard);
        layout_addBankcard=(RelativeLayout)findViewById(R.id.layout_addBankcard);

        listView_card.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            }
        });

        layout_addBankcard.setOnClickListener(this);
    }

    @Override
    protected void initData() {
        commonBeans = new CommonBeans();
        commonBeans.setUserId(String.valueOf(getSharedPreferences("UserInfo",MODE_PRIVATE).getInt("userId",0)));
        presenter.getCard(commonBeans);

    }

    @Override
    protected int getContentViewId() {
        return R.layout.activity_bankcard;
    }

    @Override
    protected Unbinder getBinder() {
        return ButterKnife.bind(this);
    }

    @Override
    protected void onChildDestroy() {
        presenter.onDetached();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public void setAdapterData(GetCardResultBeans getCardResultBeans) {
        this.getCardResultBeans = getCardResultBeans;
        bankcardListViewAdapter = new bankcardListViewAdapter(BankcardActivity.this,R.layout.item_bankcard,getCardResultBeans.getData());
        listView_card.setAdapter(bankcardListViewAdapter);
    }
}
